if (!jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.userMgt.user.Detail")) {


    /**
     *
     */
    jsx3.lang.Class.defineClass("tibco.admin.enterpriseAssets.userMgt.user.Detail",
            jsx3.gui.LayoutGrid,
            null,
            function (detail) {

				/**
				 * instance initializer
				 */
                detail.prototype.initialize = function() {
                    // set the window instance id
                    if (jsx3.lang.Class.forName("tibco.admin.enterpriseAssets.userMgt.window.Window")) {
                        this.window = this.getAncestorOfType(tibco.admin.enterpriseAssets.userMgt.window.Window)
                        if (this.window) {
                            this.setWindowId(this.window.getId());
                        }
                    }
                    // set the matrix
                    this.groupList = this.getDescendantOfName("mtxGroupList_24_C");
                    this.detailGroup = this.getDescendantOfName("lytDetailGroup_24_C");
                    //Load sub components
                    this.loadSubComponent("paneAddGroup_24_C", "tibco/admin/enterpriseAssets/userMgt/window/user/ui/searchbar.xml");
                    this.userId = "";

                    this.resetPswBtn = this.getDescendantOfName("btnResetPsw_24_C");
                    //By Paul this.removeBtn = this.getDescendantOfName("btnMask_24_C");
                    var me = this;
                    this.resetPswBtn.showResetPasswordDlg = function() {
                        me.showResetPasswordDlg();
                    }
					/*By Paul
                    this.removeBtn.doRemove = function(strRECORDID) {
                        me.callremoveGroupsForUser(strRECORDID);
                    }
					*/
					this.groupList.doRemove = function(strRECORDID) {
						me.callremoveGroupsForUser(strRECORDID);
					}
                }


				/**
				  *   set the current window ID
				  *   @para strId {string} The window id
				  */
                detail.prototype.setWindowId = function(strId) {
                    this.windowId = strId
                }

                /**
				 *   get the current window ID
				 *   @return {string} The window id
				 */
                detail.prototype.getWindowId = function() {
                    return this.windowId
                }

                /**
                 *	 The call back method while listening the "master.selectUserList" event
				 *  Including the button restriction
				 *  The isRealmWriteable and isWriteable controls the "Add Group" button
				 *  The isGetGroupsForUserEfficient controls the whole detail list
                 */
                detail.prototype.setDetails = function(objEvent) {
                    try {
                        //Set details only if the message is for the current window
                        if (objEvent.windowId == this.getWindowId()) {
                            this.getDescendantOfName("lblUserIDContent_24_C").setText(objEvent.userId, true);
                            this.userId = objEvent.userId;

                            if (objEvent.isRealmWriteable == "true") {
                                if (objEvent.isWriteable == true) {
                                    this.resetPswBtn.setEnabled(jsx3.gui.Form.STATEENABLED, true);
                                    this.getDescendantOfName("btnAddGroups_24_D_1").setEnabled(jsx3.gui.Form.STATEENABLED, true);
                                } else {
                                    this.resetPswBtn.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                                    this.getDescendantOfName("btnAddGroups_24_D_1").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                                }
                            } else {
                                this.resetPswBtn.setEnabled(jsx3.gui.Form.STATEDISABLED, true);
								this.getDescendantOfName("btnAddGroups_24_D_1").setEnabled(jsx3.gui.Form.STATEDISABLED, true);
                            }

                            if (objEvent.isGetGroupsForUserEfficient == false) {
                                this.detailGroup.setDisplay(jsx3.gui.Block.DISPLAYNONE, true);
                            }
                            else {
                                this.detailGroup.setDisplay(jsx3.gui.Block.DISPLAYBLOCK, true);
                                this.callgetAllGroupsForUser();
                            }
                        }
                    } catch(ex) {
                        tibco.admin.Main.logException(ex, "Error in tibco.admin.enterpriseAssets.userMgt.user.Detail#setDetails");
                    }
                }

				/**
				 *	  Subscribe all the events
				 */
                detail.prototype.subscribeAll = function() {
					var me = this;
					setTimeout(function(){
						tibco.admin.PubSub.subscribe(tibco.admin.enterpriseAssets.userMgt.EventID.MASTER_ROW_SELECTED, me, me.setDetails);
						},0);
                }

				/**
				 *   Unsubscribe all the events
				 */
                detail.prototype.unsubscribeAll = function() {
                    tibco.admin.PubSub.unsubscribe(tibco.admin.enterpriseAssets.userMgt.EventID.MASTER_ROW_SELECTED, this);
                }


				/**
				 *  Load sub component
				 *  @para nodeName {string} The father node
				 *  @para path {string} The sub component path
				 */
                detail.prototype.loadSubComponent = function(nodeName, path) {
                    var domeNode = this.getDescendantOfName(nodeName)
                    // Load only if dose not exists
                    if (domeNode.getChildren().length == 0) {
                        return  tibco.admin.Main.loadUIResource(domeNode, "tibco.admin", path, true);
                    }
                }

				/**
				 * The call back function of loadSubComponent
				 */
                detail.prototype.isLoaded = function(msg) {
                }


                /**
				 *  Get all the groups for a certain user - webservice call
				 */
                detail.prototype.callgetAllGroupsForUser = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/user/rules/getAllGroupsForUser.xml", "getAllGroupsForUser", "Get all groups for user");
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.ongetAllGroupsForUserSuccess);
                    //objService.subscribe(jsx3.net.Service.ON_ERROR, this, this.ongetAllGroupsForUserError);
                    //objService.subscribe(jsx3.net.Service.ON_INVALID, this, this.ongetAllGroupsForUserInvalid);
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getUserMgtEndpointURL());
                    objService.doCall();

                };

                detail.prototype.ongetAllGroupsForUserSuccess = function(objEvent) {
                    //  use transformer in matrix to map inbounddoc to cdf
                    var sourceXML = objEvent.target.getInboundDocument();
                    this.groupList.setSourceXML(sourceXML);
                    this.groupList.repaint();
                };

                detail.prototype.ongetAllGroupsForUserError = function(objEvent) {
                    var myStatus = objEvent.target.getRequest().getStatus();
                    tibco.admin.util.Log.USERMGT.error("Error, The service call failed. The HTTP Status code is: " + myStatus);
                };

                detail.prototype.ongetAllGroupsForUserInvalid = function(objEvent) {
                    tibco.admin.util.Log.USERMGT.error("Invalid, The following message node just failed validation:\n\n" + objEvent.message);
                };


				/**
				 *   Show the reset password popup window
				 */
                detail.prototype.showResetPasswordDlg = function() {
                    var loadTo = this.getAncestorOfType("tibco.admin.enterpriseAssets.userMgt.window.Window");

                    var body = tibco.admin.Main.getServer().getBodyBlock();
                    var parent = loadTo.getParent();
                    while(parent) {
                        if(parent == body) {
                            loadTo = body;
                            break;
                        }
                        parent = parent.getParent();
                    }
                    var thePopup = tibco.admin.Main.loadUIResource(loadTo, "tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/user/ui/resetPassword.xml", true);
                    thePopup.userid.setText(this.userId, true);
                }




                //==================== do save the Groups ====================
                /**
				 *	 Set the selected groups for user - webservice call
				 */
                detail.prototype.callsetGroupsForUser = function() {
                    var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/user/rules/setGroupsForUser.xml", "setGroupsForUser", "Set Groups for User");

                    //subscribe and call
                    objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.onsetGroupsForUserSuccess);
                    //objService.subscribe(jsx3.net.Service.ON_ERROR, this, this.onsetGroupsForUserError);
                    //objService.subscribe(jsx3.net.Service.ON_INVALID, this, this.onsetGroupsForUserInvalid);
                    objService.userid = this.userId;
                    objService.setEndpointURL(tibco.admin.util.ServiceHelper.getUserMgtEndpointURL());

                    objService.doCall();
                };

                detail.prototype.onsetGroupsForUserSuccess = function(objEvent) {
                };

                detail.prototype.onsetGroupsForUserError = function(objEvent) {
                    var myStatus = objEvent.target.getRequest().getStatus();
                    tibco.admin.util.Log.USERMGT.error("Error, The service call failed. The HTTP Status code is: " + myStatus);
                };

                detail.prototype.onsetGroupsForUserInvalid = function(objEvent) {
                   tibco.admin.util.Log.USERMGT.error("Invalid, The following message node just failed validation:\n\n" + objEvent.message);
                };
                //====================================================================


                //==================== do save the Groups ====================
                /**
				 *  Remove groups of a user - webservice call
				 */
                detail.prototype.callremoveGroupsForUser = function(strRECORDID) {

                    if (this.groupList.getRecordNode(strRECORDID).getAttribute("isDirectMember") == "true" && this.groupList.getRecordNode(strRECORDID).getAttribute("canEditMembers") == "true") {
                        var objService = tibco.admin.Main.loadService("tibco.admin", "tibco/admin/enterpriseAssets/userMgt/window/user/rules/removeGroupsForUser.xml", "removeGroupsForUser", "Remove Groups for User");

                        //subscribe and call
                        objService.subscribe(jsx3.net.Service.ON_SUCCESS, this, this.onremoveGroupsForUserSuccess);
                        //objService.subscribe(jsx3.net.Service.ON_ERROR, this, this.onremoveGroupsForUserError);
                        //objService.subscribe(jsx3.net.Service.ON_INVALID, this, this.onsetGroupsForUserInvalid);
                        objService.userid = this.userId;
                        objService.groupid = strRECORDID;
                        objService.setEndpointURL(tibco.admin.util.ServiceHelper.getUserMgtEndpointURL());
                        objService.doCall();
                    }
                };

                detail.prototype.onremoveGroupsForUserSuccess = function(objEvent) {
                    //jsx3.log("onremoveGroupsForUserSuccess 0 using add " + objEvent.target.simpleActionResponse)
                    if (objEvent.target.simpleActionResponse == "true") {
                        // Publish a message to window
                        var msg = new Object();
                        msg.subject = tibco.admin.enterpriseAssets.userMgt.EventID.ADD_ITEM_SUCCESS
                        msg.windowId = this.getWindowId();
                        msg.username = objEvent.target.userid;
                        tibco.admin.PubSub.publish(msg);
                    }
                    else {
                        tibco.admin.util.Log.USERMGT.error("Error", "Simple action response is " + objEvent.target.simpleActionResponse);
                    }
                };

                detail.prototype.onremoveGroupsForUserError = function(objEvent) {
					/*
                    var myStatus = objEvent.target.getRequest().getStatus();
                    tibco.admin.util.Log.USERMGT.error("Error, The service call failed. The HTTP Status code is: " + myStatus);
					*/
                };

                detail.prototype.onremoveGroupsForUserInvalid = function(objEvent) {
                    //tibco.admin.util.Log.USERMGT.error("Invalid, The following message node just failed validation:\n\n" + objEvent.message);
                };
                //====================================================================

            });
}